package cn.zxh.improvement.common.core.context;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import io.vavr.control.Option;

/**
 * 默认的应用上下文
 *
 * @author zxh
 * @since 2023-4-28 16:54:40
 */
public class DefaultContext implements Context {
    private static final Map<String, Object> BEANS = new ConcurrentHashMap<>();

    @SuppressWarnings("unchecked")
    @Override
    public <T> Option<T> getBean(String name) {
        return (Option<T>) Option.of(BEANS.get(name));
    }

    @Override
    public <T> T setBean(String name, T bean) {
        BEANS.put(name, bean);
        return bean;
    }

}
